package com.hundsun.fcp.activity;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.hundsun.fcp.R;
import com.hundsun.fcp.base.BaseActivity;
import com.hundsun.fcp.common.Redirect;
import com.hundsun.fcp.common.utils.StringUtils;
import com.hundsun.fcp.widget.EditTextWithClear;

public class MineModifyTransPwdActivity extends BaseActivity {
	    //当前密码
		private EditTextWithClear mCurPwd;
		//新密码
		private EditTextWithClear mNewPwd;
		//确认新密码
		private EditTextWithClear mConfirmPwd;
		//提交
		private Button mSubmit;
		
		private String strNewPwd;
		private String strmCurPwd;
		private String strConfirmPwd;

	protected int getContentLayout() {
		return R.layout.fcp_mine_modify_pwd;
	}
	protected void initHeader() {
		super.initHeader();
		mHeaderMenu.setTitle(R.string.mine_modify_trans_pwd);
	}
	@Override
	public void initView() {
		super.initView();
		mCurPwd = (EditTextWithClear) findViewById(R.id.et_curpwd);
		mNewPwd = (EditTextWithClear) findViewById(R.id.et_newpwd);
		mConfirmPwd = (EditTextWithClear) findViewById(R.id.et_confirmpwd);
		mSubmit = (Button) findViewById(R.id.btn_submit);
		
		mCurPwd.addTextChangedListener(mTextWatcher);
		mNewPwd.addTextChangedListener(mTextWatcher);
		mConfirmPwd.addTextChangedListener(mTextWatcher);
		
		mSubmit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				//已经判定是否为空 可直接使用
				strmCurPwd = mCurPwd.getText().toString().trim();
				strNewPwd = mNewPwd.getText().toString().trim();
				strConfirmPwd = mConfirmPwd.getText().toString().trim();
				if (strNewPwd.equals(strConfirmPwd)) {
					// TODO doModifyTransPwd();
				} else {
					//显示错误信息
					Redirect.makeToast(MineModifyTransPwdActivity.this,
							R.string.pwd_confirm_error);
				}
			}
		});
		
	}
	
	private TextWatcher mTextWatcher = new TextWatcher() {

		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
		}

		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
		}

		public void afterTextChanged(Editable s) {
			vfySignBtn();

		}
	};

	/**
	 * 根据是否输入当前密码、新密码、确认新密码来控制确认按钮
	 */
	private void vfySignBtn() {
		strmCurPwd = mCurPwd.getText().toString().trim();
		strNewPwd = mNewPwd.getText().toString().trim();
		strConfirmPwd = mConfirmPwd.getText().toString().trim();

		if (StringUtils.isEmpty(strmCurPwd) || StringUtils.isEmpty(strNewPwd)
				|| StringUtils.isEmpty(strConfirmPwd)) {
			mSubmit.setEnabled(false);
			mSubmit.setBackgroundResource(R.drawable.btn_grey_unable);
		} else {
			mSubmit.setEnabled(true);
			mSubmit.setBackgroundResource(R.drawable.btn_red_normal);
		}
	}


}
